var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    officelist: [],
    typs: "",
    isLoading: !0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var hid = options.hid
    var pinyin = options.pinyin
    var tit = options.tit
    var typs = options.typs;
    var leixing = options.leixing;
    var tid = options.id;
    var money = options.money;
    var name = options.name;
    if (name != '' && name != undefined) {
      that.setData({
        name: name
      })
    }
    if (money != '' && money != undefined) {
      that.setData({
        money: money
      })
    }
    if (leixing != '' && leixing != undefined) {
      that.setData({
        leixing: leixing
      })
    }
    if (tid != '' && tid != undefined) {
      that.setData({
        tid: tid
      })
    }
    if (typs != undefined) {
      that.setData({
        typs: typs
      })
    }
    if (options.j_id) {
      var j_id = options.j_id
      that.setData({
        j_id: options.j_id
      })
    }
    if (options.conets) {
      var conets = JSON.parse(options.conets)
      that.setData({
        conets: conets
      })
    }

    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    this.getAlldepartment()
    wx.setNavigationBarTitle({
      title: '科室选择',
    })
    that.setData({
      hid: hid,
      pinyin: pinyin,
      tit: tit
    })
  },
  toorder() {
    var that = this;
    var hid = that.data.hid
    var pinyin = that.data.pinyin
    var typs = that.data.typs;

    var tit = that.data.tit

    var name = that.data.name
    var conets = JSON.stringify(that.data.conets)
    var j_id = that.data.j_id
    var leixing = that.data.leixing;
    var tid = that.data.tid;
    var openid = wx.getStorageSync('openid')
    if (openid == '') {
      wx.showModal({
        cancelColor: '提示',
        content:"请先登录",
        success:function(con){
          if(con.confirm)
          {
            wx.navigateTo({
              url: '/hyb_yl/sgin/sgin',
            })
          }else{
            wx.switchTab({
              url: '/hyb_yl/tabBar/index/index',
            })
          }
        }
      })
      
    } else{
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/zhuanjiatiwens/zhuanjiatiwens?leixing=lvtong&tit=' + tit + '&tid=' + tid + '&keshi_two=&hid=' + hid + '&server=' + pinyin + '&leixing=' + leixing + '&money=' + that.data.money + '&name=' + name + '&did=&zid=',
      })
    }
    
  },
  handleTap(e) {
    var that = this
    console.log(e)
    var hid = that.data.hid
    var pinyin = that.data.pinyin

    var id = e.currentTarget.dataset.id
    var typs = that.data.typs;
    if (that.data.tit) {
      var tit = that.data.tit
    } else {
      var tit = e.currentTarget.dataset.tit
    }
    var name = that.data.name
    var conets = JSON.stringify(that.data.conets)
    var j_id = that.data.j_id
    var leixing = that.data.leixing;
    console.log(leixing)
    var tid = that.data.tid;
    if (leixing == 'lvtong') {
      wx.navigateTo({
        url: '/hyb_yl/userCommunicate/pages/changeDoctors/changeDoctors?tit=' + tit + '&tid=' + tid + '&id=' + id + '&hid=' + hid + '&ser_key=' + pinyin + '&leixing=' + leixing + '&money=' + that.data.money + '&name=' + name + '&zid=',
      })
    } else if(that.data.typs=='index'){
      var pages = getCurrentPages();
      var prePage = pages[pages.length-2];
      prePage.setData({
        parentid:id,
        keshi:tit
      })
      wx.navigateBack({})
    } else {
      wx.navigateTo({

        url: '/hyb_yl/userCommunicate/pages/changeDoctor/changeDoctor?tit=' + tit + '&long=' + this.data.long + '&id=' + id + '&hid=' + hid + '&ser_key=' + pinyin + '&conets=' + conets + '&j_id=' + j_id + '&typs=' + typs,
      })
    }

  },
  /**
   * 生命周期函数--监听页面初次渲染完成   
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getAlldepartment() {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/faxian.departments',
      data: {},
      success: function (res) {
        console.log(res)
        var officelist = res.data
        that.setData({
          officelist: officelist,
          isLoading: !1
        })
      }
    })
  },
  searclass(e) {
    console.log(e)

  },
  shop_search_function(e) {
    console.log(e)
    var that= this
    var value = e.detail.value
    app.util.request({
      'url': 'entry/wxapp/faxian.departments',
      data: {
        keywords:value
      },
      success: function (res) {
        console.log(res)
        var officelist = res.data
        that.setData({
          officelist: officelist,
          isLoading: !1
        })
      }
    })
  }
})